package danran.regular;

import java.util.Arrays;

/**
 * @Classname RemoveElement
 * @Description TODO
 * @Date 2021/10/13 21:58
 * @Created by ASUS
 */
public class RemoveElement {
    public int removeElement(int[] nums, int val) {
        int left = 0, right = nums.length - 1;
        while (left <= right) {
            if (nums[left] == val) {
                // move the array
                System.arraycopy(nums, left + 1, nums, left, right - left);
                right--;
            } else left++;
        }
        return right + 1;
    }

    public int strStr(String haystack, String needle) {
        return haystack.indexOf(needle);
    }

    public int divide(int divid, int divis) {
        long ans = 0;
        if (divis == 1) return divid;
        if (divis == -1) {
            if (divid == Integer.MIN_VALUE) return Integer.MAX_VALUE;
            else return -divid;
        }
        long dividend = divid, divisor = divis;
        int f = 1;
        if (dividend > 0 && divisor < 0 || dividend < 0 && divisor > 0) f = -1;
        dividend = dividend < 0 ? -dividend : dividend;
        divisor = divisor < 0 ? -divisor : divisor;
        while (dividend >= divisor) {
            dividend -= divisor;
            ans++;
        }
        if (f == -1) {
            if (ans > Integer.MAX_VALUE) return Integer.MIN_VALUE;
            else return (int) -ans;
        }
        if (ans > Integer.MAX_VALUE) return Integer.MAX_VALUE;
        else return (int) ans;
    }

    public static void main(String[] args) {
//        System.out.println(new RemoveElement().removeElement(new int[]{3, 2, 2, 3}, 3));
        System.out.println(new RemoveElement().divide(-2147483648, -1));
    }
}
